<script setup>
import {onMounted, ref} from "vue";
import {useStore} from "../../pinia/index.js";
import {post} from "../../util/request.js";
import {useRouter} from "vue-router";

const router = useRouter()
const store = useStore()
const description = ref('');
const complaintType = ref('视频无法播放'); // 默认选择不友善内容
const videoInfo=ref({})
const onSubmit = () => {
  // 发送请求到后端接口
  post('course/feedback', {
    complaintType: complaintType.value,
    description: description.value,
    openCourseVideoId: videoInfo.value.courseId,
  })
      .then(response => {
        if (response.code == 0) {
          alert('反馈成功')

          router.go(-1)


        } else {
          alert("反馈失败")
        }
      }, error => {
        console.error('Error creating article:', error);
        // 处理错误逻辑
      });
}

onMounted(()=>{
  videoInfo.value = store.openVideoCourseInfo;
})
const onClickLeft = ()=>history.back();

</script>

<template>
  <van-nav-bar fixed   border   left-text="返回" @click-left="onClickLeft" />
<h1>  视频反馈</h1>
  <div>
    <van-form @submit="onSubmit">
      <!-- 单选按钮组，每个选项将在新的一行显示 -->
      <van-field name="radio" label="反馈类型">
        <template #input>
          <van-radio-group v-model="complaintType">
            <van-radio name="视频无法播放">视频无法播放</van-radio>
            <van-radio name="视频画面花瓶">视频画面花瓶</van-radio>
            <van-radio name="视/音频不同步">视/音频不同步</van-radio>
            <van-radio name="字幕不同步">字幕不同步</van-radio>
            <van-radio name="播放不流畅">播放不流畅</van-radio>

          </van-radio-group>
        </template>
      </van-field>

      <!-- 文本输入区 -->
      <div class="text-input">
        <h3>反馈内容：</h3>
        <van-field v-model="description" rows="4" autosize type="textarea" maxlength="200" placeholder="请提供相应的证据，以便我们处理。" show-word-limit/>
      </div>

      <!-- 图片上传 -->
<!--      <div class="image-upload">-->
<!--        <p>添加照片证据（至少1张）：</p>-->
<!--        <van-uploader :after-read="handleRead" :max-size="5 * 1024 * 1024" upload-text="点击上传"/>-->
<!--      </div>-->

      <!-- 提交按钮 -->
      <div class="button-container">
        <van-button type="primary" size="large" @click="onSubmit">提交</van-button>
      </div>
    </van-form>
  </div>

</template>

<style scoped>

</style>